var noticeData, viewImgs = ["/share/img/btn_view_more.jpg", "/share/img/btn_view_close.jpg"],
listTpl = enco.util.createTemplate(
	'<tr>' +
	'<td><input type="checkbox" class="chk" name="chkItem" value="{ntcSeq}"></td>' +
	'<td>{ntcSeq}</td>' +
	'<td>{ntcTypeNm}</td>' +
	'<td class="left">{ttl}</td>' +
	'<td>{regrEmpNo}</td>' +
	'<td>{regYmdt}</td>' +
	'<td><a href="javascript:;" onclick="doDetail({index}, this);"><img src="/share/img/btn_view_more.jpg"></a></td>' +
	'</tr>' +
	'<tr id="{index}" style="display: none;">' +
	'<td></td>' +
	'<td colspan="5">' +
	'<div class="tbl_type3">' +
	'	<table cellspacing="0" border="1">' +
	'	<col width="120">' +
	'	<col>' +
	'	<col width="120">' +
	'	<col width="120">' +
	'	<tr><th>제목</th><td class="left">{ttl}</td><th>등록일시</th><td>{regYmdt}</td></tr>' +
	'	<tr><th>내용</th><td class="left" colspan="3"><textarea style="border:0px;width:100%; overflow-y:auto;" rows="20" readonly>{cont}</textarea></td></tr>' +
	'	</table>' +
	'</div>' +
	'</td>' +
	'<td></td>' +
	'</tr>',
	'<tbody>'
),
noListTpl = enco.util.createTemplate(
	'<tr>' +
	'<td colspan="7">검색된 데이터가 없습니다.</td>' +
	'</tr>',
	'<tbody>'
);

$(document).ready(function(){
	$(".svc").checkSelect("svcAll", false); 
	$(".svcAll").checkAll("svc", false);
	
	$(".chk").checkSelect("chkAll", false); 
	$(".chkAll").checkAll("chk", false);
	
	$("#loading").ajaxStart(function(){
	    $.blockUI({ 
	        message: $(this), 
	        css: { 
	            top:  ($(window).height() - 100) /2 + 'px', 
	            left: ($(window).width() - 400) /2 + 'px', 
	            width: '400px' 
	        } 
	    });
	}).ajaxComplete(function(){
		 setTimeout($.unblockUI, 100);
	});
});

function doSearch(page) {
	
	var params = {
		page: (page == undefined) ? 1 : page,
		ntcTypeCd: $("#ntcTypeCd").val(),
		delYn: $('input[name="delYn"]:checked').val(),
	};
	
	enco.log(params);

	$.get("/etc/notice/search", params, function(result){
		noticeData = JSON.parse(result).noticeList;
		var len = noticeData.length;
		var total = JSON.parse(result).total;
		var target = document.getElementById("noticeList");
		
		if(len > 0) {
			for(var i=0;i<len;++i){
				noticeData[i].index = i;
				listTpl.append(null, noticeData[i]);
			}
			listTpl.flush(target, "overwrite");
		} else {
			noListTpl.overwrite(target, null);
		}
		
		$("#total").text(total);
		
		enco.util.paginate(JSON.parse(result).paginate)
 				.flush(document.getElementById("paginate"));
	});

	return false;
}

function doDetail(index, that) {
	if($(that).children().attr("src") == viewImgs[0]) {
		$("#" + index).show();
		$(that).children().attr("src", viewImgs[1]);
	} else {
		$("#" + index).hide();
		$(that).children().attr("src", viewImgs[0]);
	}
}